package GUI;
/**
 * Management type user main menu
 */

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class ManagmentMainMenu extends JFrame {
	
	public Login myLoginFrame = null;
	public UserManagment user=null;
	private ManagmentSelParent blockParentScrn = null;
	private ManagmentSelParentUnblock unBlockParentScrn = null;
	
	public ManagmentMainMenu() {
		setTitle("Managment Main Menu");
		setSize(600,600);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnUserControl = new JMenu("User control");
		menuBar.add(mnUserControl);
		
		JMenuItem mntmBlockUser = new JMenuItem("Block user");
		mntmBlockUser.addActionListener(new ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				user.data.Parents=null;
				myLoginFrame.client.handleMessageFromClientUI("ParentQueryForManagment notblocked");
				while(user.data.Parents==null);
				blockParentScrn = null;
				blockParentScrn =  getBlockParentScrn();
				setContentPane(blockParentScrn);
				
				
			}
		});
		mnUserControl.add(mntmBlockUser);
		
		JMenuItem mntmUnblockUser = new JMenuItem("Unblock user");
		mntmUnblockUser.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				user.data.Parents=null;
				myLoginFrame.client.handleMessageFromClientUI("ParentQueryForManagment blocked");
				while(user.data.Parents==null);
				unBlockParentScrn = null;
				unBlockParentScrn =  getUnBlockParentScrn();
				setContentPane(unBlockParentScrn);
			}
		});
		mnUserControl.add(mntmUnblockUser);
		
		JMenuItem mntmLogout = new JMenuItem("Logout");
		mntmLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				System.out.println("logout");
				if(myLoginFrame.LoginResult.equalsIgnoreCase("OK"))
				{
					myLoginFrame.client.handleMessageFromClientUI("logout "+myLoginFrame.UserName.getText().toString());
				}
				myLoginFrame.UserName.setText("");
				myLoginFrame.Password.setText("");
				myLoginFrame.setContentPane(myLoginFrame.getFirstPanel());
				myLoginFrame.setVisible(true);
				//idTextField.setText("");
				//userTypeTextField.setText("");
				myLoginFrame.LoginResult=null;
				myLoginFrame.UserType=null;
				setVisible(false);
			}
		});
		menuBar.add(mntmLogout);
	}

	public void setParents(Vector<ParentClass> p)
	{
		this.user.data.Parents=p;
	}
	public ManagmentSelParent getBlockParentScrn()
	{
		  
		 if(blockParentScrn==null)
		 {
			 blockParentScrn = new ManagmentSelParent(this);
			 blockParentScrn.myLoginFrame = myLoginFrame;
			 blockParentScrn.mmn=this;
			 blockParentScrn.setSize(getMaximumSize());
			 
			 
		 }
		 
		 return blockParentScrn;
	}
	
	public ManagmentSelParentUnblock getUnBlockParentScrn()
	{
		  
		 if(unBlockParentScrn==null)
		 {
			 unBlockParentScrn = new ManagmentSelParentUnblock(this);
			 unBlockParentScrn.myLoginFrame = myLoginFrame;
			 unBlockParentScrn.mmn=this;
			 unBlockParentScrn.setSize(getMaximumSize());
			 
		 }
		 
		 return unBlockParentScrn;
	}
	
	public void updateApproveToParentalBlock(boolean b)
	{
		this.user.Executed=b;
	}
}
